<template>

  <el-upload :action="baseURL+'api/NationImport'"
             :accept="accept"
             :limit="limit"
             :on-success="SuccessFile"
             :before-remove="RemoveFile"
             :on-exceed="UpExceed"
             :before-upload="BeforeUpExcel"
             :headers="{ AuthToken: token }"
             name="Files"
             :data="upData"
             :file-list="fileList">
    <el-button size="small"
               type="primary">点击上传</el-button>
    <div slot="tip"
         class="tip">{{ tip }}</div>
  </el-upload>
</template>
<script>
import API from '../../../api/index'; //读入restfulAPI
import { mapState, mapMutations } from 'vuex';
export default {
  name: 'nationFileUpload',
  props: {
    accept: String,
    limit: Number,
    tip: String,
    id: String
  },
  data () {
    return {
      upData: {},
      fileList: []
    };
  },
  created () { },
  watch: {},
  computed: mapState(['token', "baseURL"]),
  methods: {
    Clear () {
      this.upData = {};
      this.fileList = [];
    },
    BeforeUpExcel (file) {
      this.upData = { Name: file.name, id: this.id };
      return this.$nextTick();
    },
    UpExceed (files, fileList) {
      this.$message.warning(`当前限制选择 ${this.limit} 个文件，已经选择了 ${files.length + fileList.length} 个文件`);
    },
    SuccessFile (response, file, fileList) {
      let excelData = [];
      excelData = fileList[0].response.detail
      this.$emit('update:excelData', excelData);
    },
    RemoveFile (file, fileList) {

    }
  }
};
</script>

<style scoped>
</style>